export const tags = {
  input: {
    component: 'el-input',
    attrs: {
      placeholder: '请输入',
      clearable: true,
      class: 'form-control-ml',
    },
  },
  autocomplete: {
    component: 'c-autocomplete',
    attrs: {
      placeholder: '请输入',
      clearable: true,
      class: 'form-control-ml',
    },
  },
  number: {
    component: 'el-input',
    attrs: {
      min: 0,
      type: 'number',
      class: 'form-control-ml',
    },
  },
  select: {
    component: 'c-select',
    attrs: {
      placeholder: '请选择',
      clearable: true,
      class: 'form-control-ml',
    },
  },
  date: {
    component: 'el-date-picker',
    attrs: {
      placeholder: '选择日期',
      clearable: true,
      type: 'date',
      'value-format': 'yyyy-MM-dd',
      class: 'form-control-ml',
    },
  },
  radio: {
    component: 'el-radio',
  },
  'radio-group': {
    component: 'c-radio-group',
  },
  checkbox: {
    component: 'el-checkbox',
  },
  'checkbox-group': {
    component: 'c-checkbox-group',
    value: [],
  },
  cascader: {
    component: 'el-cascader',
    attrs: {
      placeholder: '请选择',
      clearable: true,
      class: 'form-control-ml',
    },
  },
  textarea: {
    component: 'el-input',
    attrs: {
      type: 'textarea',
      class: 'form-control-ml',
    },
  },
  upload: {
    component: 'upload-oss',
    attrs: {
      multiple: true,
      accept: 'image/*',
      dir: 'chick',
      listType: 'picture-card',
    },
  },
}

function parseFloatFilterNan(value) {
  const val = Number.parseFloat(value)
  return isNaN(val) ? value : val
}

export function toOptions(obj, isNumberKey) {
  return Object.keys(obj).map(key => {
    const value = isNumberKey ? parseFloatFilterNan(key) : key
    const label = obj[key]
    return { value, label }
  })
}
